package com.koron.standard.rating.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koron.standard.rating.bean.po.RatingItem;
import com.koron.standard.rating.mapper.RatingItemMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 评级标准从表(RatingItem)表服务实现类
 *
 * @author jzp
 * @since 2022-01-04
 */
@Service
public class RatingItemService extends ServiceImpl<RatingItemMapper, RatingItem> {
    public List<RatingItem> listByRatingId(String ratingId) {
        LambdaQueryWrapper<RatingItem> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RatingItem::getRatingId, ratingId);
        wrapper.orderByAsc(RatingItem::getSort);
        return list(wrapper);
    }

    public List<RatingItem> listByRatingIds(List<String> ratingIds) {
        LambdaQueryWrapper<RatingItem> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(RatingItem::getRatingId, ratingIds);
        return list(wrapper);
    }

    public void removeByRatingId(String ratingId) {
        if (StrUtil.isEmpty(ratingId)) {
            return;
        }
        LambdaQueryWrapper<RatingItem> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RatingItem::getRatingId, ratingId);
        List<RatingItem> list = list(wrapper);
        removeByIds(list.stream().map(RatingItem::getId).collect(Collectors.toList()));
    }
}
